<template>
  <div class="main2">
    <img src="../assets/images/log1.jpg">
    <div class="login">
      <ul>
        <li>
          <p>用户名</p>
          <input type="text" v-model.trim="user.username">
        </li>
        <li>
          <p>密码</p>
          <input type="password" v-model.trim="user.psw">
          <a href="#">忘记密码？</a>
        </li>
      </ul>
    </div>
    <div class="loginok">
      <a @click="loginhandler">登 录</a>
      <router-link to="/Register" class="register">注 册</router-link>
    </div>
    <div class="indfoot">
      <p style="text-align:center;">版权所有 佛山市电子口岸有限公司</p>
    </div>
  </div>
</template>

<script>
import { cookie, md5 } from "vux";
// import md5 from "blueimp-md5";
export default {
  name: "Login",
  data() {
    return {
      user: {
        username: "",
        psw: ""
      }
    };
  },
  methods: {
    loginhandler() {
      // console.info("login--", this.user);
      if (!this.user.username) {
        this.$vux.toast.text("请输入用户名");
        return;
      }
      if (!this.user.psw) {
        this.$vux.toast.text("请输入密码");
        return;
      }
      let { username, psw } = this.user;
      psw = md5(psw, "fseport", false);
      // console.info("psw-------", psw);
      // console.info("fc1f57f1b9cd809b2b5328be7a709802");
      // "/wxtoken/login?loginName=admin&password=fc1f57f1b9cd809b2b5328be7a709802&code=1"

      // return;
      this.$http({
        url: "/wxtoken/login",
        method: "post",
        params: {
          loginName: username,
          password: psw,
          code: 1
        }
      }).then(result => {
        console.info("result---", result);
        // let result = resp.data;
        if (result.code === 200) {
          this.$vux.toast.text("登录成功");
          //保存用户信息到cookie
          cookie.set("userinfo", JSON.stringify(result.data));
          this.$router.replace("/Home");
        } else {
          this.$vux.toast.text("登录失败");
        }
      });
    }
  },
  mounted() {
    console.info("router--", this.$router);
  }
};
</script>


